package com.group56.view.userend.book_module;


import com.group56.CoachDetail;
import com.group56.MainApp;
import com.group56.factory.AppCMFactory;
import com.group56.model.dao.Impl.CoachDAOImpl;
import com.group56.model.entity.Coach;
import com.group56.utils.FXMLSrcMenu;
import com.group56.utils.FXMLViewHandler;
import com.group56.view.FrameworkController;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import com.group56.ScheduleModuleApp;
import com.group56.UserInfoModuleApp;
import com.group56.factory.AppCMFactory;
import com.group56.factory.UserModuleCMFactory;
import com.group56.utils.FXMLSrcMenu;
import com.group56.utils.FXMLViewHandler;
import com.group56.view.FrameworkController;
import com.group56.view.ViewController;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import lombok.SneakyThrows;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class CoachListController implements Initializable {

    @FXML private VBox list;

    @FXML private Button video_button;

    @FXML
    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        Coach coach;
        int i=1;
        int num=1;
        CoachDAOImpl coachDAO= new CoachDAOImpl();
        while (true){
            coach = coachDAO.selectByID(String.valueOf(i++));
            if (coach != null)
                list.getChildren().add(addCoach(coach,num));
            else
                break;
            num++;
        }
    }


    @FXML
    public Pane addCoach(Coach coach, int num){
        Pane pane=new Pane();
        Image image=new Image(coach.getPicUrl());
        ImageView imageView=new ImageView();
        imageView.setImage(image);
        imageView.setFitHeight(160);
        imageView.setFitWidth(240);
        imageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @SneakyThrows
            @Override
            public void handle(MouseEvent mouseEvent) {
                CoachDetailController.coachID=num+"";
                FrameworkController appFramework = (FrameworkController) AppCMFactory.getCtrlrMediator().getController(FXMLSrcMenu.UserEnd.APP_FRAMEWORK.getSrc());
                FXMLViewHandler.putViewInPane(appFramework.getContentPane(),FXMLViewHandler.getView(FXMLSrcMenu.UserEnd.COACH_DETAIL.getSrc()));
                System.out.println("here");
            }
        });

        Label label=new Label(coach.getName()+"\n"+coach.getDetail());
        label.setLayoutX(280);
        label.setLayoutY(50);
        pane.getChildren().add(label);
        pane.getChildren().add(imageView);
        return pane;
    }
}

